<?php

namespace App\Http\Middleware;

use App\Models\Traits\LastActivedAtHelper;
use Closure;
use Auth;

/**
 * 记录用户登录的最后的时间
 *
 * Class RecordLastActivedTime
 * @package App\Http\Middleware
 */
class RecordLastActivedTime
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // 如果用户登录的话
        if (Auth::check()) {
            // 记录用户登录的时间
            user()->recordLastActivedAt();
        }
        return $next($request);
    }
}
